var mongoose = require('mongoose');
require('../model/dish.model');
var dishModel = mongoose.model('Dish');

module.exports={
    findByMerchantId:findByMerchantId,
    findByMerchantIdAndType:findByMerchantIdAndType,
    findByMerchantIdAndName:findByMerchantIdAndName,
    findByAll:findByAll
};


function findByMerchantId(mid,callBack){
    dishModel.find({'mid':mid},function (err,doc) {
        callBack(err,doc);
    });
}

function findByMerchantIdAndType(mid,type,callBack){
    dishModel.find({'mid':mid,'type':type},function (err,doc) {
        callBack(err,doc);
    });
}

function findByMerchantIdAndName(mid,name,callBack){
    dishModel.find({'mid':mid,'name':{$regex:name,$options:'i'}},function (err,doc) {
        callBack(err,doc);
    });
}

function findByAll(mid,type,name,callBack){
    dishModel.find({'mid':mid,'type':type,'name':{$regex:name,$options:'i'}},function (err,doc) {
        callBack(err,doc);
    });
}